package org.clockworkmages.games.anno1186.situations.sexsettings;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.GameData;
import org.clockworkmages.games.anno1186.GameDataService;
import org.clockworkmages.games.anno1186.GameStateService;
import org.clockworkmages.games.anno1186.model.Fetish;
import org.clockworkmages.games.anno1186.model.option.GoBackOption;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.model.situation.Situation;
import org.clockworkmages.games.anno1186.situations.sexsettings.options.EnableDisableSexSettingOption;

public class SexSettingsSituation
		extends Situation {
	private GameStateService gameStateService;
	private GameDataService gameDataService;

	public SexSettingsSituation() {
		super("ST_SEXSETTINGS");
		setTitle("SexSettings!");
		setClearScreen(true);

		gameStateService = GameBeansContext.getBean(GameStateService.class);
		gameDataService = GameBeansContext.getBean(GameDataService.class);
	}

	@Override
	public void update() {
		super.update();

		GameData gameData = gameDataService.getGameData();

		Set<String> enabledFetishes = gameStateService.getGameState()
				.getFetishesEnabled();

		String text = " This is where you can select your sexual preferences and fetishes!\n"
				+ " {f:b}By default, all sexual preferences are disabled{f} so as not to bombard the users with filth and perversion unless they want to be bombarded with it. "
				+ "Nevertheless, sex is an important part of this game and activating additional preferences will unlock many additional dialogue options and random events.\n"
				+ " Even with all sex options disabled the game is still playable and fun, but don't be surprised if you'll go visit a brothel run by mermaids, demonesses and harpies and the only dialogue option you'll get inside will be 'Uh, nice weather, isn't it?'. On the other hand, with 'Sex with women', 'Mythical creatures' and 'Submission' options enabled, things will likely get much more interesting.\n"
				+ //
				"\n"
				+ //
				"You currently have "
				+ (enabledFetishes.isEmpty() ? "no fetishes enabled."
						: "the following fetishes enabled:\n\n");

		List<String> lsEnabledFetishes = new ArrayList<String>(enabledFetishes);
		Collections.sort(lsEnabledFetishes);
		for (String fetishId : enabledFetishes) {
			Fetish fetish = gameData.getFetishes().get(fetishId);
			text += fetish.getName() + "\n";
		}

		setText(text);

		List<Option> options = getOptions();
		options.clear();
		options.add(GoBackOption.INSTANCE);

		List<Fetish> fetishes = new ArrayList<Fetish>(gameData.getFetishes()
				.values());
		Collections.sort(fetishes);

		for (Fetish fetish : fetishes) {
			boolean isEnabled = enabledFetishes.contains(fetish.getId());
			options.add(new EnableDisableSexSettingOption(fetish, isEnabled));
		}

		options.add(GoBackOption.INSTANCE);

	}
}
